package com.example.makerspace.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.makerspace.domain.ApplicationDO;
import com.example.makerspace.mapper.ApplicationMapper;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

@Component
public class ApplicationDAO extends BaseDAO<ApplicationDO>{

    @Resource
    private ApplicationMapper applicationMapper;

    @PostConstruct
    public void init(){
        this.mapper = applicationMapper;
    }

    public final static String USERNAME = "username";

    public ApplicationDO selectByUsername(String username){
        return applicationMapper.selectOne(new QueryWrapper<ApplicationDO>().eq(USERNAME, username));
    }

    public List<ApplicationDO> selectAll(){
        return applicationMapper.selectList(null);
    }

    public List<ApplicationDO> selectLatest(Integer num){
        return applicationMapper.selectList(new QueryWrapper<ApplicationDO>().orderByDesc("create_time").last("limit " + num));
    }
}
